package com.tydic.workflow.service.impl;

import com.tydic.common.core.domain.model.LoginUser;
import com.tydic.common.satoken.utils.LoginHelper;
import com.tydic.workflow.common.constant.ProcessVariableKey;
import com.tydic.workflow.service.IBpmService;
import com.tydic.workflow.service.IEnterpriseRegisterService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
@RequiredArgsConstructor
public class EnterpriseRegisterServiceImpl extends AuditServiceImpl implements IEnterpriseRegisterService {

    private final IBpmService bpmService;

    @Override
    public ProcessInstance startProcess(String businessKey) {
        LoginUser user = LoginHelper.getLoginUser();
        Map<String, Object> variables = new HashMap<>();
        variables.put(ProcessVariableKey.STARTER, user.getUserCode());
        bpmService.setAuthenticatedUserId(user.getLoginCode());
        return bpmService.startProcessInstanceByKey("enterprise_register", businessKey, variables);
    }

    @Override
    protected IBpmService getBpmService() {
        return bpmService;
    }
}
